<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  
</body>
<script>
  // 做饭
  function cook(){
    console.log('做饭')
    var p = new Promise(function(resolve,reject){
      setTimeout(function(){
        console.log('做饭完毕')
        resolve('鸡蛋炒饭')
      },1000)
    })
    return p;
  }
  // 吃饭
  function eat(data){
    console.log('开始吃饭'+data)
    var p = new Promise(function(resolve,reject){
      setTimeout(function(){
        console.log('吃饭完毕')
        resolve('一个碗和一双筷子')
      },1000)
    })
    return p;
  }
  // 洗碗
  function wash(data){
    console.log('开始洗碗'+data)
    var p = new Promise(function(resolve, reject){
      setTimeout(function(){
        console.log('洗碗完毕')
        resolve('干净的碗筷')
      })
    })
    return p;
  }
  // 使用.then方法调用这三个函数
  cook().then(function(data){
    return eat(data);
  })
  .then(function(data){
    return wash(data);
   
  })
  .then(function(data){
    console.log(data)
  })

  // .then方法的简写
  // cook().then(eat).then(wash).then(function(data){
  //   console.log(data)

  // })
</script>
</html>